package com.example.capsule_netty.netty;

import com.example.capsule_netty.protocol.MessageBeanDecoder;
import com.example.capsule_netty.protocol.MessageBeanEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhuzhiming
 * @Date: 2022/4/27 19:41
 */
public class NettyInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline()
                .addLast("encoder", new MessageBeanEncoder())
                .addLast("decoder", new MessageBeanDecoder())
                .addLast(new IdleStateHandler(60, 60, 120, TimeUnit.SECONDS))
                .addLast(new NettyHandler());
    }
}
